package com.qys.livesMall.shop.modal.vo;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

@Data
public class ShopStatisticsInfoVo {

    /***************用户信息*************/

    @Schema(description = "用户显示Id（用户账号）")
    private String userRandomId;

    @Schema(description = "用户Id")
    private Long userId;

    @Schema(description = "用户名")
    private String userName;

    @Schema(description = "昵称")
    private String nickName;

    @Schema(description = "上级用户名称")
    private String superiorName;

    @Schema(description = "代理用户名称")
    private String agentAccount;
    /******店铺信息***************/
    @Schema(description = "店铺id")
    private Long shopId;

    @Schema(description = "会员层级")
    private String storey;

    @Schema(description = "VIP等级")
    private String vipLevel;

    @Schema(description = "店铺编码")
    private String shopCode;

    @Schema(description = "店铺名")
    private String shopName;
    /**
     * 创建时间
     */
    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    @Schema(description = "手机号")
    private String phone;

    /**
     * 小店类型（1：正常店铺 2：水军店铺）
     */
    @Schema(description = "小店类型（1：正常店铺 2：水军店铺）")
    private String type;
    /**
     * 状态（0：正常 1：待审批  2：待发合同 ，3:关店申请，4，已关店，-1，审批不通过,-2,冻结）
     */
    @Schema(description = "状态（0：正常 1：待审批  2：待发合同 ，3:关店申请，4，已关店，-1，审批不通过,-2,冻结）")
    private String status;


    /**
     * 电话的国家代码
     */
    @Schema(description = "电话的国家代码")
    private String phoneCountryCode;

    @Schema(description = "申请IP")
    private String applyIp;

    @Schema(description = "余额")
    private BigDecimal availableBalance;

    /*******店铺统计*********/

    @Schema(description = "充提差额")
    private BigDecimal difference;

    @Schema(description = "充值金额")
    private BigDecimal recharge;

    @Schema(description = "提现金额")
    private BigDecimal withdrawal;

    @Schema(description = "是否充值")
    private Integer recharged = 0;

    @Schema(description = "首冲时间")
    private LocalDateTime firstCharge;

    @Schema(description = "首冲天数")
    private long firstChargeDay;

    @Schema(description = "充值次数")
    private Integer rechargeNumber;

    @Schema(description = "提现次数")
    private Integer withdrawalNumber;

    @Schema(description = "今日订单数")
    private Integer todayOrderNum;

    @Schema(description = "店铺订单总数量")
    private Integer orderNumber;

    @Schema(description = "同行为IP数")
    private Integer sameRegisterIpNum;

    @Schema(description = "钱包地址")
    private String walletAddress;

    @Schema(description = "店铺库存额")
    private BigDecimal stocksAmount;

    @Schema(description = "店铺库存量")
    private BigDecimal stocksNum;

    @Schema(description = "今日店铺收益")
    private BigDecimal todayIncome;

    @Schema(description = "累计店铺收益")
    private BigDecimal cumulative;

    @Schema(description = "店铺进货后付优惠金额")
    private BigDecimal discountAmount;


    @Schema(description = "最后操作IP")
    private String lastIp;

    @Schema(description = "最后操作时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+0")
    private LocalDateTime lastOperateTime;


    /*******团队******/
    @Schema(description = "直推人数")
    private Integer directNumber;

    @Schema(description = "2代人数")
    private Integer twoNumber;


    @Schema(description = "3代人数")
    private Integer threeNumber;

    @Schema(description = "团队人数")
    private String lastThreeNum;

    @Schema(description = "注册人数")
    private Integer lastThreeRegisterNum;

    @Schema(description = "团队充提差")
    private BigDecimal lastThreeDifference;

    @Schema(description = "团队待审核提现")
    private BigDecimal lastThreeWaitWithdrawal;

    @Schema(description = "已过期数")
    private Integer expireNumber;

    @Schema(description = "30天新增")
    private Integer recentAdd;

    @Schema(description = "30过期人数(自己下面的1.2.3代 余额小于20+真实用户+状态正常+充值用户)")
    private Integer expireRecent;

    @Schema(description = "团队复充金额(1-n代)")
    private BigDecimal teamRepeatedRecharge;
    @Schema(description = "团队提现金额(自己的1-n代)")
    private BigDecimal teamWithdrawal;

    @Schema(description = "近3代复充金额(1-3代)")
    private BigDecimal lastThreeGenRecharge;

    @Schema(description = "近3代提现金额自己的1.2.3代）")
    private BigDecimal lastThreeWithdrawal;


    @Schema(description = "备注")
    private String notes;



    @Schema(description = "今日团队收益")
    private BigDecimal todayTeamIncome;

    @Schema(description = "累计团队收益")
    private BigDecimal totalTeamIncome;


    public void setRecharge(BigDecimal recharge) {
        if(recharge==null){
            return;
        }
        this.recharged=0;
        if (recharge.compareTo(BigDecimal.ZERO)>0){
            this.recharged=1;
        }
        this.recharge = recharge;

    }


    public Long getFirstChargeDay() {
        if(createTime!=null&&firstCharge!=null) {
            return LocalDateTimeUtil.between(createTime, firstCharge, ChronoUnit.DAYS);
        }
        return null;
    }

    public Integer getTodayOrderNum() {
        if (todayOrderNum==null){
            return 0;
        }
        return todayOrderNum;
    }

    public BigDecimal getTodayIncome() {
        if (todayIncome==null){
            return BigDecimal.ZERO;
        }
        return todayIncome;
    }
}
